package org.acghub.mtdb.xmlgen.visitor;

import org.acghub.mtdb.common.Bean;
import org.acghub.mtdb.common.Type;
import org.acghub.mtdb.common.Var;
import org.acghub.mtdb.common.Visitor;
import org.acghub.mtdb.common.type.TypeBaseCollection;
import org.acghub.mtdb.common.type.TypeBaseMap;
import org.acghub.mtdb.common.type.TypeBasePrimitives;
import org.acghub.mtdb.util.StringUtil;

import java.io.PrintStream;

public class VarDeclareVisitor implements Visitor {

    private final Var var;
    private final PrintStream ps;
    private final String prefix;

    public VarDeclareVisitor(Var var, PrintStream ps, String prefix) {
        this.var = var;
        this.ps = ps;
        this.prefix = prefix;
    }

    private void make(Type type) {
        if (StringUtil.isNotEmpty(var.getComment())) {
            ps.println(prefix + StringUtil.getPrintComment(var.getComment()));
        }
        ps.println(prefix + "private " + type.javaInterfaceType() + " " + var.getName() + ";");
        ps.println();
    }

    @Override
    public void visit(TypeBasePrimitives type) {
        make(type);
    }

    @Override
    public void visit(TypeBaseCollection type) {
        make(type);
    }

    @Override
    public void visit(TypeBaseMap type) {
        make(type);
    }

    @Override
    public void visit(Bean bean) {
        make(bean);
    }
}
